package com.xuedakun.xasdk.net.volley;

import com.android.volley.Request;
import com.android.volley.toolbox.StringRequest;
import com.xuedakun.xasdk.net.HttpUtils;


/**
 * Created by xuedakun on 2017/6/3 15:22
 * http post请求
 * @version : v1.0
 * @project : xasdk
 * @Email : dakun611@Gmail.com
 */

public class PostRequest<R extends BaseResult> extends AbstractRequest<R> {

    /**
     * 请求主体构造
     *
     * @param host     请求网络接口的host
     * @param method   请求网络接口的方法名
     * @param callback 请求回调
     */
    public PostRequest(String host, String method, VolleyCallback<R> callback) {
        super(host, method, callback);
    }

    @Override
    protected StringRequest getRealRequest() {
        if(stringRequest == null) {
            stringRequest = new StringRequest(Request.Method.POST, getUrl(), callback, callback);
        }
        return stringRequest;
    }

    @Override
    protected String getUrl() {
        String url = host + HttpUtils.URL_DELIMITER + method;
        for(Object urlArgument : urlArguments) {
            url += HttpUtils.URL_DELIMITER + urlArgument.toString();
        }
        return url;
    }
}
